<!--
 * @Author: wangding
 * @Date: 2020-11-16 17:07:33
 * @LastEditTime: 2021-05-11 14:22:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\deviceUpgrade\deviceUpgrade.vue
-->
<template>
    <div class="deviceUpgrade-main-box">
        <div class="search-box">
            <div class="search-box-sub">
                <span class="lable-text">{{$t('device-update-group1')}}</span>
                <el-select v-model="addGroupName" filterable :placeholder="$t('please_choose')" clearable @change='groupChange'>
                    <el-option
                        v-for="item in groupNameList"
                        :key="item.sid"
                        :label="item.groupName"
                        :value="item.sid">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub">
                <span class="lable-text">{{$t('equipmentClassify')}}</span>
                <el-select v-model="type" filterable :placeholder="$t('please_choose')" clearable @change='typeChange'>
                    <el-option
                        v-for="item in typeNameList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub" v-if='type == 3'>
                <span class="lable-text">{{$t('battery.firmName')}}</span>
                <el-select v-model="brand" filterable :placeholder="$t('please_choose')" clearable @change='batterTypeChange'>
                    <el-option
                        v-for="item in dictionary.BATTERY_BRAND"
                        :key="item.value"
                        :label="item.code"
                        :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub" v-if='type'>
                <span class="lable-text">{{$t('version.versionAdd.compatible')}}</span>
                <el-select v-model="value" filterable :placeholder="$t('please_choose')" clearable @change='valueChangeType'>
                    <el-option
                        v-for="item in valueList"
                        :key="item.value"
                        :label="item.code"
                        :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub" v-if='type == 1&& value'>
                <span class="lable-text">{{$t('device-update-program')}}</span>
                <el-select v-model="newType" filterable :placeholder="$t('please_choose')" clearable @change='valueChange'>
                    <el-option
                        v-for="item in upgradeSection"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub" v-if='type && newType != 6&& value'>
                <span class="lable-text">{{$t('version.versionAdd.versions')}}</span>
                <el-select v-model="versions" filterable :placeholder="$t('please_choose')" clearable @change='versionsChange'>
                    <el-option
                        v-for="item in versionsList"
                        :key="item.id"
                        :label="item.text"
                        :value="item.id">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub" v-if='newType == 6'>
                <span class="lable-text">{{$t('update.DSP')}}</span>
                <el-select v-model="dVersion" filterable :placeholder="$t('please_choose')" clearable @change='versionsChangeNew'>
                    <el-option
                        v-for="item in versionsListDsp"
                        :key="item.id"
                        :label="item.text"
                        :value="item.id">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub" v-if='newType == 6 '>
                <span class="lable-text">{{$t('update.ARM')}}</span>
                <el-select v-model="aVersion" filterable :placeholder="$t('please_choose')" clearable @change='versionsChangeNew'>
                    <el-option
                        v-for="item in versionsListArm"
                        :key="item.id"
                        :label="item.text"
                        :value="item.id">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub">
                <!-- <el-button type="primary" @click='updateGetUpdatePage(1)'>{{$t('test.deviceTest.historyTest.refresh')}}</el-button> -->
            </div>
            <div class="search-box-sub right">
                <el-button icon="el-icon-back" @click='()=>{this.$router.go(-1)}' >{{$t('back')}}</el-button>
            </div>
        </div>
        <div class="button-box">
            <el-button type="primary"  icon='el-icon-upload2' class="marginR10" @click='addMoadl'>{{$t('devWifi.batchUpgrade')}}</el-button>
            <!-- <a href="javascript:;" style="color:#3c8dbc;" @click='()=>{$router.push({path:"/deviceUpgrade"})}'> << {{$t('device-back-remote-update-index')}}</a> -->
        </div>
        <div class="pos-box-main"><i class="el-icon-refresh-right pos-box" style="font-size:30px;"  @click='updateGetUpdatePage(1)' :title="$t('test.deviceTest.historyTest.refresh')"></i></div>
        <baseTable v-loading="loadingTable"  row-key='sid' :data="dataRows" border  stripe :column='column' :select='true' @selection-change="handleSelectionChange($event)" :max-height='fullHeight-210'
        ref="multipleTable"
        >
            <template #deviceType="{data}">
                <span>{{comm.returnCode(dictionary.SCOPE_TO,data.deviceType)}}</span>
            </template>
            <template #siteName="{data}">
                <!-- <router-link :to="{name:'overview_site', query:{ siteId: data.siteIds,siteName:data.siteName }}" target="_blank" class="hover-a-link" style="color:#ED7523;">{{data.siteName}}</router-link> -->
                <a href="javascript:;" class="hover-a-link" style="color:#ED7523;" @click="openRouter({path:'/overview_site', query:{ siteId: data.siteIds,siteName:data.siteName }})">{{data.siteName}}</a>
            </template>
            <template #deviceSN="{data}">
                <a href="javascript:;" class="hover-a-link" style="color:#ED7523;" @click='openSnDetail(data)'>{{data.deviceSN}}</a>
            </template>
            <template #inverterType="{data}">
                <span>{{comm.returnCode(dictionary.INVERTER_TYPES,data.inverterType)}}</span>
            </template>
            <template #brandVersionFormatter="{data}">
                <span>{{brandVersionFormatter(data)}}</span>
            </template>
            <template #armVersion="{data}">
                <span>{{formatterValuearm(data.armVersion,data)}}</span>
            </template>
            <template #progress="{data}">
                <span>{{returnProgress(data)}}</span>
            </template>
            <template #enableFlag="{data}">
                <span :style='data.enableFlag==1?"color:#429dff":""'>
                    <i class="iconfont icon-wifi" style="vertical-align: middle;" ></i>
                    {{comm.returnCode(dictionary.ON_LINE_STATE,data.enableFlag)}}
                </span>
            </template>
            <template #option="{data}">
                <div class="option-box" v-if='returnUserFlag'>
                    <el-button style='font-size:18px;' type="" icon='el-icon-upload' :title="$t('report.UpdateMode')" @click='showEditModal(data)'></el-button>
                    <el-button style='font-size:18px;'  v-if='data.updateFlag == 1' type="" icon='el-icon-refresh-left' :title="$t('reset.button')" @click='wifiEditEntity(data)'></el-button>
                </div>
            </template>
        </baseTable>
        <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination> -->
        <add v-if='newVisible' @uploadData='query' :addValueList='addValueList' :selectDataList='selectDataList' :inverterType='type ==1?newType:type' :scope='value'></add>
    </div>
</template>

<script>
let timeOutId = ''
import add from '../add'
import baseTable from '../../../../components/common/baseTable'
export default {
    components: {
        baseTable,
        add
    },
    props: {

    },
    data() {
        return {
            addGroupName:'',
            newType:'',
            groupNameList:[],
            typeNameList:[{
                id:'1',
                name: this.$t('inverter')
            },{
                id:'2',
                name: this.$t('installationGuide.commSelect')
            },{
                id:'3',
                name: this.$t('devicd.display.Battery')
            }],
            upgradeSection:[{
                id:'1',
                name:'ARM'
            },{
                id:'3',
                name:'DSP'
            },{
                id:'5',
                name: this.$t('update.slaverDSP')
            },{
                id:'6',
                name: this.$t('inverter-overall')
            }],
            inverterSn:'',
            dictionary:{},
            type:"",
            valueList:'',
            brand:'',
            value:'',
            versions:'',
            loading:false,
            scopeUserData:'',
            groupList:[],
            versionsList:[],
            versionsListDsp:[],
            versionsListArm:[],
            loadingTable:false,
            size:10,
            current:1,
            total:1,
            dataRows:[],
            column:[{
                title: this.$t('devWifi.loginName'),
                value: 'loginName',
            },
            {
                title: this.$t('site'),
                value: 'siteName',
                slot: 'siteName',
                min_width:'190'
            },
            {
                title: this.$t('devWifi.deviceSN'),
                value: 'deviceSN',
                slot: 'deviceSN',
                min_width:'120'
            },{
                title: this.$t('devWifi.wifiSN'),
                value: 'wifiSN',
                slot: 'wifiSN',
                min_width:'100'
            },
            {
                title: this.$t('device-communication-type'),
                value: 'deviceType',
                slot: 'deviceType',
            },
            {
                title: this.$t('devWifi.deviceType'),
                value: 'inverterType',
                slot: 'inverterType',
            },{
                title: this.$t('update.batteryModel'),
                value: 'batterySlaverType',
                slot: 'brandVersionFormatter',
            },
            {
                title: this.$t('devWifi.wifiVersion'),
                value: 'wifiVersion',
                slot: 'wifiVersion',
            },
            {
                title: this.$t('update.ARM'),
                value: 'armVersion',
                slot: 'armVersion',
            },
            {
                title: this.$t('update.DSP'),
                value: 'inverterVersion',
                slot: 'inverterVersion',
                min_width:localStorage.getItem('lang') == 'en_US'? '100': '100'
            },
            {
                title: this.$t('update.slaverDSP'),
                value: 'inverterSlaverVer',
                slot: 'inverterSlaverVer',
                min_width:localStorage.getItem('lang') == 'en_US'? '130': '100'
            },{
                title: this.$t('update.batteryM'),
                value: 'batteryMasterVer',
                min_width:localStorage.getItem('lang') == 'en_US'? '140': '100'
            },
            {
                title: this.$t('update.batteryS'),
                value: 'batterySlaverVer',
                slot: 'batterySlaverVer',
                min_width:localStorage.getItem('lang') == 'en_US'? '140': '100'
            },
            {
                title: this.$t('device.inverter.enableFlag'),
                value: 'enableFlag',
                slot: 'enableFlag',
            },
            {
                title: this.$t('devUpgrade.upgradeStatus'),
                value: 'progress',
                slot: 'progress',
            }],
            agentId:'',
            siteName:'',
            deviceSN:'',
            wifiSN:'',
            subGroupId:'',
            selectDataList:[],
            addValueList:[],
            updatingSNsArr:[],
            doUpdataArr:[],
            timeOutId:'',
            editInverter:null,
            editWifiSn:'',
            aVersion:'',
            dVersion:'',
            rowEditData:{},
            fullHeight: document.documentElement.clientHeight
        };
    },
    computed: {
        returnUserType(){
            return localStorage.getItem('userType')
        },
        newVisible(){
            return this.$store.state.sysStore.newVisible
        }
    },
    watch: {

    },
    beforeDestroy(){
        //页面销毁前清除计时器
        window.clearTimeout(this.timeOutId)
    },
    created() {

    },
    mounted() {
        this.upgradegroupGetGroupList()
        this.getDictionaryBatch()
        this.deviceGetSubGroupName()
        // this.updateGetUpdatePage()
        const that = this
        window.onresize = () => {
            return (() => {
            window.fullHeight = document.documentElement.clientHeight
            that.fullHeight = window.fullHeight
            })()
        }
    },
    methods: {
        openRouter(params){
            let url=this.$router.resolve(params)
            window.open(url.href,'_blank')
        },
        async upgradegroupGetGroupList(){
            let res = await this.API.upgradegroupGetGroupList()
            this.groupNameList = res
            this.addGroupName = this.groupNameList.length>0?this.groupNameList[0].sid : ''
            this.updateGetUpdatePage()
        },
        groupChange(){
            this.updateGetUpdatePage()
            this.value = ''
            this.type = ''
            this.newType = ''
            this.brand = ''
            this.versions = ''
            this.valueList = []
            this.versionsList = []
        },
        async addGroupMoadl(){
            if(this.selectDataList.length == 0){
                this.comm.showMsg(false, this.$t('device-chose-add-data'))
                return
            }
            this.$store.commit('setVisibleAdd',true)
        },
        async openSnDetail(data){
            let res = await this.API.deviceGetPage({
                SN: data.deviceSN,
                size: 10,
                current: 1
            })
            data = res.rows[0] || []
            sessionStorage.setItem("selRow_inverterType",data.inverterType);
            sessionStorage.setItem("selRow_siteid",data.siteIds);
            sessionStorage.setItem("selRow_inverter_sn",data.SN);
            sessionStorage.setItem("selRow_wifi_sn",data.wifiSN);
            sessionStorage.setItem("selRow_firmId",data.firmIds || '');
            sessionStorage.setItem("selRow_sn_type",2);//逆变器
            sessionStorage.setItem("selRow_phase_type",data.phaseFlag);
            sessionStorage.setItem("selRow_battery_type",data.batteryFlag);
            sessionStorage.setItem("selRow_load_type",data.loadFlag);
            sessionStorage.setItem("selRow_siteId",data.siteIds);
            sessionStorage.setItem("selRow_batteryTypeFlag",data.batteryType);//电池类型
            sessionStorage.setItem("selRow_userId",data.userIds);
            sessionStorage.setItem("selRow_epsStatus",data.epsStatus);
            
            let url = this.$router.resolve({
                path: "/overview-inverter",
            });
            window.open(url.href, '_blank');
        },
        showEditModal(data){
            this.editInverter=data.inverterType
            this.editWifiSn=data.wifiSN
            this.rowEditData = data
            this.$store.commit('setNewVisibleEdit',true)
        },
        returnUserFlag(){
            let userType = localStorage.getItem('userType')
            if(userType == 1 || userType == 2){
                return true
            }else{
                return false
            }
            
        },
        async updateGetUpdateProgressByWifis(){
            //此方法主作更新的循环机制，用于实时更新更新的进度
            let res = await this.API.updateGetUpdateProgressByWifis({
                wifiSNs:this.updatingSNsArr.join()
            })
            this.doUpdataArr = JSON.parse(res)
            
            if(this.doUpdataArr.length>0){
                this.doUpdataArr.forEach(item =>{
                    let str = ''
                    let devSn=item.name;
                    let progress=item.value;
                    let successFlag=item.successFlag;
                    var wifiVersion=item.wifiVersion || '';
					var armVersion=item.armVersion || '';
					var inverterVersion=item.inverterVersion || '';
                    if(successFlag=='0'){
                        str = this.$t('devUpgrade.fialUpgrade')
                        this.updatingSNsArr.splice(this.updatingSNsArr.indexOf(devSn),1)
                    }else if(successFlag==2){
                        if(item.value && item.value != '100'){
                            str = this.$t('devUpgrade.download') + `${progress}%`
                        }else if(item.value == '100'){
                            str = this.$t('devUpgrade.downfinish')
                            this.updatingSNsArr.splice(this.updatingSNsArr.indexOf(devSn),1)
                        }
                    }else if(successFlag==1||successFlag==3){
                        str = this.$t('version.versionAdd.succeed')
                        this.dataRows.forEach(item =>{
                            if(item.wifiSN == devSn){
                                //这里，由于vue的双向数据绑定的缺陷，无法监听到对象以及数组的变化，需手动通知vue响应机制来监听数据变化
                                this.$set(item,'updateFlag',0)
                                // this.$set(item,'armVersion',armVersion)
                                // this.$set(item,'wifiVersion',wifiVersion)
                                // this.$set(item,'inverterVersion',inverterVersion)
                                this.$set(item,'updateStatusFlag','1')
                            }
                        })

                        this.updatingSNsArr.splice(this.updatingSNsArr.indexOf(devSn),1)
                    }else if(successFlag==4){
                        str = ' - '
                    }else if(successFlag==5){
                        str = this.$t('devUpgrade.download') + ` 0%`
                    }
                    this.dataRows.forEach(item =>{
                        if(item.wifiSN == devSn){
                            this.$set(item,'progress',str)
                            this.$set(item,'showUpdataFlag',true)
                        }
                    })
                })
                window.clearTimeout(this.timeOutId)
                this.timeOutId = window.setTimeout(()=>{
                    this.updateGetUpdateProgressByWifis()
                },5*1000)
            }
        },
        returnProgress(data){
            //此方法作用：
            //1、将table列表里面正在更新的数据的wifisn，push到更新的数据里面
            //2、对列表的数据进行判断，初步渲染更新状态
            let updateStatusFlag=data.updateStatusFlag;
            let updateFlag=data.updateFlag;
            let progress=data.progress;
            let wifiSN=data.wifiSN;
            // this.updatingSNsArr = []
            if(!data.showUpdataFlag){
                if(updateFlag == 1){
                if(progress==101){
                        if (this.updatingSNsArr.indexOf(wifiSN) == -1) {
                            this.updatingSNsArr.push(wifiSN);
                        }
                        return this.$t('devUpgrade.download') +' 0%'
                    }else{
                        if(updateStatusFlag=='0'){//0下载失败
                            return this.$t('devUpgrade.fialUpgrade')
                        }else if(updateStatusFlag==2){
                            if (this.updatingSNsArr.indexOf(wifiSN) == -1) {
                                this.updatingSNsArr.push(wifiSN);
                            }
                            if(progress&&progress!=this.$t('devUpgrade.downfinish')&&progress!=100){	
                                return this.$t('devUpgrade.download') +` ${progress}%`
                            }else if(progress==this.$t('devUpgrade.downfinish')||progress==100){
                                return this.$t('devUpgrade.downfinish')
                            }
                            
                        }else if(updateStatusFlag==1){
                            return this.$t('devUpgrade.downfinish')
                        }else if(updateStatusFlag==null){
                            return ' - '
                        }
                    }
                }else if(updateFlag=='0'){
                    if(updateStatusFlag==null){
                        return ' - '
                    }else if(updateStatusFlag=='0'){
                        return this.$t('devUpgrade.fialUpgrade')
                    }else{
                        return this.$t('devUpgrade.downfinish')
                    }
                }else if(updateFlag==null){
                    return ' - '
                }
            }else{
                return data.progress
            }
            
        },
        async wifiEditEntity(data){
            let res = await this.API.wifiEditEntity({
                id: data.ids,
                updateFlag: 0,
                updateStatusFlag: 0
            })
            //重置操作时先把该条数据从更新栈里面去除
            this.updatingSNsArr.splice(this.updatingSNsArr.indexOf(data.wifiSN),1)
            this.updateGetUpdatePage()
        },
        async updateGetVersionByType(){
            if(!(this.type && this.value)){
                this.$message({
                message: this.$t('devUpgrade.pleaseChooseFirst'),
                type: 'warning'
                });
                return 
            }
            if(this.type == 1){
                if(!this.newType){
                    this.$message({
                    message: this.$t('device-ple-choose-update-item'),
                    type: 'warning'
                    });
                    return 
                }
            }
            if(!(this.selectDataList.length >0)){
                this.$message({
                message: this.$t('device-ple-choose-update-data'),
                type: 'warning'
                });
                return 
            }
            let flag = true
            this.selectDataList.forEach(item =>{
                if(item.updateFlag == 0){
                    flag = false
                }
            })
            if(flag){
                this.$message({
                message: this.$t('devUpgrade.pleaseDelete'),
                type: 'warning'
                });
                return 
            }
            let res = await this.API.updateGetVersionByType({
                type: this.type == 1? this.newType:this.type,
                type: this.type == 3 ? 4:this.type == 1?this.newType:this.type,
                value: this.value == 11 || this.value == 12 ? 10 : this.value,
                brand:this.brand,
                ids:this.selectDataList.map(item => {
                    return item.ids
                })
            })
            
            this.addValueList = res
            this.$store.commit('setNewVisible',true)
        },
        addMoadl(){
            this.updateGetVersionByType()
        },
        formatterValuearm(value,row){
            if(value){
                if(row.loaderVersion&&row.loaderVersion!='null'&&row.loaderVersion){
                    return value==null||value=='null'? "-":value+'-'+row.loaderVersion
                }else{
                    return value==null||value=='null'?'-':value
                }
            }
        },
        brandVersionFormatter(row){
            let bv = ''
            if(row.batteryBrand != null && row.batterySlaverType != null){
                bv = parseInt(row.batteryBrand) * 10 +  parseInt(row.batterySlaverType);
                return this.comm.returnCode(this.dictionary.BATTERY_BRAND_VERSION, bv);
            }else{
                return '-';
            }
        },
        async updateGetUpdatePage(val){
            this.loadingTable = true
            let res = await this.API.upgradegroupwifiGetPage({
                // siteName: this.siteName,
                // wifiSN: this.wifiSN,
                // deviceSN: this.deviceSN,
                // wifiVersion: this.versions,
                // type: this.type,
                // value: this.value,
                // isSub: localStorage.getItem('userType') == 2?1:0,
                // subGroupId: this.subGroupId,
                // brand: this.brand,
                upgradeGroupId:this.addGroupName,
                size: 200,
                current: 1

            })
            
            this.updatingSNsArr = []
            this.dataRows = res.rows
            this.dataRows.forEach(item =>{
                item['showUpdataFlag'] = false
            })
            this.loadingTable = false
            this.total = res.total
            //启动计时器前，必须清除之前的计时器，避免多个计时器运行
            window.clearTimeout(this.timeOutId)
            //element table的数据渲染要耗时，这里给一个短暂计时器，避免获取更新的wifisn组为空，----暂时没有找到element table数据渲染后的回调钩子，如有，可以替换下面计时器，提高响应效率
            this.timeOutId = window.setTimeout(()=>{
                if(this.updatingSNsArr.length > 0){
                    this.updateGetUpdateProgressByWifis()
                }
            },0.5*1000)
            this.$nextTick(()=>{
                // console.log(this.$refs.multipleTable,'this.$refs.multipleTable');
                let checkboxDom = document.querySelectorAll('.el-checkbox__original')
                checkboxDom.forEach(item =>{
                    item.disabled = true
                    item.setAttribute('style','cursor:no-drop;')
                })
            })
            if(val == 1){
                this.upgradegroupwifiGetPageSelect(1)
            }
        },
        async updateGetVersions(){
            if(this.type == 1&&!this.newType){
                this.versionsList = []
                return
            }
            if(this.type == 1&&!this.value){
                this.versionsList = []
                return
            }
            this.versions = ''
            let res = await this.API.updateGetVersions({
                type:this.type == 1?this.newType:this.type,
                value:this.value,
                brand:this.brand,
            })
            // res.shift()
            this.versionsList = res || []
        },
        async deviceGetSubGroupName(){
            let res = await this.API.deviceGetSubGroupName()
            this.groupList = res || []
        },
        async updateGetUpdateAgent(query){
            this.loading = true
            let res = await this.API.updateGetUpdateAgent({
                firmName:query
            })
            this.scopeUserData = res || []
            this.loading = false
        },
        query(){
            this.current = 1
            
            this.updateGetUpdatePage()
        },
        typeChange(){
            if(this.type == '1'){
                this.valueList = this.dictionary.INVERTER_TYPES
                this.brand = ''
                this.value = ''
            }
            if(this.type == '2'){
                this.brand = ''
                this.value = ''
                this.valueList = this.dictionary.SCOPE_TO
            }
            // if(this.type == '3'){
            //     this.brand = ''
            //     this.valueList = this.dictionary.INVERTER_TYPES
            // }
            if(this.type == '3'){
                this.valueList = []
                this.value = ''
            }
            if(!this.type){
                this.brand = ''
                this.valueList = ''
                this.value = ''
            }
            this.versions = ''
            this.dVersion = ''
            this.aVersion = ''
            for(let i = 0;i<this.dataRows.length;i++){
                this.$refs.multipleTable.$children[1].toggleRowSelection(this.dataRows[i],false)
            }
            // this.updateGetVersions()
            // this.updateGetUpdatePage()
        },
        batterTypeChange(){
            if(this.brand == 81){
                this.valueList = this.dictionary.BATTERY_VERSION_81
            }
            if(this.brand == 82){
                this.valueList = this.dictionary.BATTERY_VERSION_82
            }
            if(this.brand == 83){
                this.valueList = this.dictionary.BATTERY_VERSION_83
            }
            if(this.brand == 84){
                this.valueList = this.dictionary.BATTERY_VERSION_84
            }
            if(this.brand == 129){
                this.valueList = this.dictionary.BATTERY_VERSION_129
            }
            if(!this.brand){
                this.valueList =[]
                for(let i = 0;i<this.dataRows.length;i++){
                    this.$refs.multipleTable.$children[1].toggleRowSelection(this.dataRows[i],false)
                }
            }
            this.value = ''
            // this.updateGetVersions()
        },
        valueChangeType(){
            // this.updateGetUpdatePage()
            this.updateGetVersions()
            if(this.type!=1 && this.value){
                this.upgradegroupwifiGetPageSelect()
            }
            if(this.type ==1 && this.value && this.newType){
                this.upgradegroupwifiGetPageSelect()
            }
            if(this.type ==1 && this.value && this.newType == 6){
                this.updateGetVersionsD()
                this.updateGetVersionsA()
            }
            
            if(!this.value){
                this.newType = ''
                this.versions = ''
                this.dVersion = ''
                this.aVersion = ''
            }

            if(!this.value || !this.newType){
                for(let i = 0;i<this.dataRows.length;i++){
                    this.$refs.multipleTable.$children[1].toggleRowSelection(this.dataRows[i],false)
                }
                //再次禁用
                this.$nextTick(()=>{
                    let checkboxDom = document.querySelectorAll('.el-checkbox__original')
                    checkboxDom.forEach(item =>{
                        item.disabled = true
                        item.setAttribute('style','cursor:no-drop;')
                    })
                })
            }
        },
        valueChange(){
            // this.updateGetUpdatePage()
            this.updateGetVersions()
            if(this.type!=1 && this.value){
                this.upgradegroupwifiGetPageSelect()
            }
            if(this.type ==1 && this.value && this.newType){
                this.upgradegroupwifiGetPageSelect()
            }
            if(this.type ==1 && this.value && this.newType == 6){
                this.updateGetVersionsD()
                this.updateGetVersionsA()
            }

            if(!this.newType){
                this.versions = ''
                this.dVersion = ''
                this.aVersion = ''
            }

            if(!this.value || !this.newType){
                for(let i = 0;i<this.dataRows.length;i++){
                    this.$refs.multipleTable.$children[1].toggleRowSelection(this.dataRows[i],false)
                }
                //再次禁用
                this.$nextTick(()=>{
                    let checkboxDom = document.querySelectorAll('.el-checkbox__original')
                    checkboxDom.forEach(item =>{
                        item.disabled = true
                        item.setAttribute('style','cursor:no-drop;')
                    })
                })
            }
        },
        versionsChangeNew(){
            // if(this.aVersion){
            //     this.versions = this.aVersion
            // }
            // if(this.dVersion){
            //     this.versions = this.dVersion
            // }
            this.upgradegroupwifiGetPageSelect()
        },
        async updateGetVersionsD(){
            let res = await this.API.updateGetVersions({
                type:3,
                value:this.value
            })
            this.versionsListDsp = res
        },
        async updateGetVersionsA(){
            let res = await this.API.updateGetVersions({
                type:1,
                value:this.value
            })
            this.versionsListArm = res
        },
        versionsChange(){
            this.upgradegroupwifiGetPageSelect()
        },
        async upgradegroupwifiGetPageSelect(val){
            if(val == 1){
                if(!this.value){
                    return
                }
            }
            let res = await this.API.upgradegroupwifiGetPage({
                // siteName: this.siteName,
                // wifiSN: this.wifiSN,
                // deviceSN: this.deviceSN,
                upgradeGroupId:this.addGroupName,
                wifiVersion: this.versions == this.$t('all')?"":this.versions,
                aVersion: this.aVersion == this.$t('all')?"":this.aVersion,
                dVersion: this.dVersion == this.$t('all')?"":this.dVersion,
                type: this.type == 3 ? 4:this.type == 1?this.newType:this.type,
                value: this.value,
                // isSub: localStorage.getItem('userType') == 2?1:0,
                // subGroupId: this.subGroupId,
                // inverterModel:this.newType,
                brand: this.brand,
                size: 200,
                current: 1
            })
            //清空选中
            // console.log(this.$refs.multipleTable.$children[1].toggleRowSelection,'this.$refs.multipleTable');
            for(let i = 0;i<this.dataRows.length;i++){
                this.$refs.multipleTable.$children[1].toggleRowSelection(this.dataRows[i],false)
            }
            for(let i = 0;i<this.dataRows.length;i++){
                for(let j = 0;j<res.rows.length;j++){
                    if(this.dataRows[i].deviceSN == res.rows[j].deviceSN){
                        this.$refs.multipleTable.$children[1].toggleRowSelection(this.dataRows[i],true)
                    }
                }
            }
            this.$nextTick(()=>{
                // console.log(this.$refs.multipleTable,'this.$refs.multipleTable');
                let checkboxDom = document.querySelectorAll('.el-checkbox__original')
                checkboxDom.forEach(item =>{
                    item.disabled = true
                    item.setAttribute('style','cursor:no-drop;')
                })
            })
            // res.rows.forEach(item =>{
            //     this.$refs.multipleTable.$children[0].toggleRowSelection(item,true)
            // })
        },
        async getDictionaryBatch(){
            let res = await this.API.getDictionaryBatch({
                dictCodes:'SCOPE_TO,INVERTER_TYPES,DEVICE_CLASSIFY,PUBLISH_STATUS,BATTERY_VERSION,BATTERY_BRAND,BATTERY_VERSION_81,BATTERY_VERSION_82,BATTERY_VERSION_83,BATTERY_VERSION_84,BATTERY_BRAND_VERSION,ON_LINE_STATE,BATTERY_VERSION_129',
                lang:localStorage.getItem('lang')||'zh_CN'
            })
            this.dictionary = res || {}
        },
        handleSizeChange(val) {
          this.size = val
          this.current = 1
          this.updateGetUpdatePage()
        },
        handleCurrentChange(val) {
          this.current = val
          this.updateGetUpdatePage()
        },
        handleSelectionChange(val){
          this.selectDataList=val
        },
    },
};
</script>

<style  lang="less">
.deviceUpgrade-main-box{
    
    .hover-a-link:hover{
        text-decoration: underline;
    }
    .el-checkbox__input,
    .el-checkbox__inner{
        cursor:not-allowed;
    }
    .has-gutter  .el-checkbox{//找到表头那一行，然后把里面的复选框隐藏掉
        display:none !important;
    }
    .pos-box-main{
        position: relative;
        .pos-box{
            position: absolute;
            top: 0;
            right: 35px;
            color: #a1a1a1;
        }
    }
}
</style>
